 layui.use(['common', 'layer', 'table', 'form', ], function() {
     var $ = layui.$,
         layer = layui.layer,
         form = layui.form,
         common = layui.common,
         table = layui.table;
     var tableIns = table.render({
         elem: '#userList', //指定原始表格元素选择器（推荐id选择器）
         cols: [
             [{
                 field: 'userId',
                 align: 'center',
                 title: 'ID',
                 sort: true,
             }, {
                 field: 'username',
                 align: 'center',
                 title: '账号',
             }, {
                 field: 'realname',
                 align: 'center',
                 title: '姓名',
             }, {
                 field: 'avatar',
                 align: 'center',
                 title: '头像',
             }, {
                 field: 'phone',
                 align: 'center',
                 title: '手机号',
             }, {
                 field: 'email',
                 align: 'center',
                 title: '邮箱',
             }, {
                 field: 'sex',
                 align: 'center',
                 title: '性别',
                 templet: '#sexTpl',
             }, {
                 field: 'locked',
                 align: 'center',
                 title: '状态',
                 templet: '#lockedTpl',
             }, {
                 align: 'center',
                 title: '操作',
                 toolbar: '#userBar'
             }]
         ], //设置表头
         url: '/systemsetup/permissionsmanage/user/findPagingQuery',
         page: true,
         loading: true,
         limits: [10, 30, 60, 90, 150, 300],
         limit: 10 //默认采用60
     });
          $('#addUser').on('click', function() {
         layer.open({
             type: 2,
             shadeClose: true,
             title: '添加管理员',
             maxmin: true, //开启最大化最小化按钮
             area: ['720px', '550px'],
             content: ['/systemsetup/permissionsmanage/user/addIndex/', 'yes'],
             end: function() {
                 tableIns.reload();
             },
         });
     });
     //监听性别操作
     form.on('switch(sex)', function(obj) {
         layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
     });
     //监听锁定操作
     form.on('checkbox(locked)', function(obj) {
        
    	 
    	 $.post("/systemsetup/permissionsmanage/user/updataDisableAdminUser",{id:this.value},function(result){
    	 		if (result.status == 200) {
    	 			tableIns.reload();
    			   } else {
    				   layer.msg(result.msg);
    			   } 
    	 	});
     });
     //监听工具条
     table.on('tool(userList)', function(obj) {
         var data = obj.data;
         console.log(data);
         if (obj.event === 'detail') {
             layer.open({
                 type: 2,
                 title: "查看角色",
                 area: ['600px', '430px'], //宽高
                 content: "/systemsetup/permissionsmanage/user/detailIndex?id=" + data.userId,
                 end: function() {
                     tableIns.reload();
                 }
             });
         } else if (obj.event === 'del') {
             layer.confirm('确定要删除吗', {
                 btn: ['确定', '取消'] //按钮
             }, function() {
                 $.post("/systemsetup/permissionsmanage/user/delectAdminUser", {
                     id: data.roleId
                 }, function(result) {
                     if (result.status == 200) {
                         layer.msg(result.msg, {
                             time: 2000,
                         });
                     } else {
                         layer.msg(result.msg, {
                             time: 2000,
                         });
                     }
                     tableIns.reload();
                 });
             }, function() {
                 tableIns.reload();
             });
         } else if (obj.event === 'edit') {
             layer.open({
                 type: 2,
                 title: "编辑角色",
                 area: ['600px', '480px'], //宽高
                 content: "/systemsetup/permissionsmanage/user/editIndex?id=" + data.userId,
                 end: function() {
                     tableIns.reload();
                 }
             });
         }
     });
 });